chk2 column.visible=false
讀值時,讀到空白string xxx = GridView5.Rows[0].Cells[2].Text .ToString();
<asp:GridView ID="GridView5" runat="server" AutoGenerateColumns="False" >
<Columns>
<asp:BoundField DataField="xxx" HeaderText="xxx" SortExpression="xxx" />
<asp:BoundField DataField="chk" HeaderText="chk" SortExpression="chk"/>
<asp:BoundField DataField="chk2" HeaderText="chk2" SortExpression="chk2" Visible="False"/>
</Columns>
</asp:GridView>
聽說是因為visible=false,col就沒有被bind.
所以要等bind之後,再把它visible
<asp:GridView ID="GridView5" runat="server" AutoGenerateColumns="False" >
<Columns>
<asp:BoundField DataField="xxx" HeaderText="xxx" SortExpression="xxx" />
<asp:BoundField DataField="chk" HeaderText="chk" SortExpression="chk"/>
<asp:BoundField DataField="chk2" HeaderText="chk2" SortExpression="chk2"/>
</Columns>
</asp:GridView>
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header || e.Row.RowType == DataControlRowType.DataRow)
{
//要隱藏的欄位
e.Row.Cells[2].Visible = false;
}
}